<?php

$this->session->set_flashdata('num',10);
?>
<script type="text/javascript">
function prueba(){
var anos; 
  var num = $("#fecha2").val().substring(0,2);
 return anos =  $("#fecha2").val().substring(6,10)+','+num+','+$("#fecha2").val().substring(3,5);
   	
} 
</script>
<div id="error"><?php echo @$mensage; ?>
</div>
<script language="javascript">
    var applyFilter = function(){
        jQuery("#list").setGridParam({
            url: '/controlinterno/data/',
            page:1,
            postData:{
                search: true,
                name: $('#name').val(),
                dispara_fin:$('.f_fin:checked').val()
            }
        });
    }

    jQuery(document).ready(function(){
        jQuery("#list").jqGrid({
            url: '<?php echo site_url() ?>/controlinterno/data/',
            mtype: 'POST',
            datatype: 'json',
            colNames:['ID','Referencia', 'Servicio','Status S.','Etapa','Dias P.','Dias E.','Contacto','Telefono','C-Etapa'],
            colModel :[
                {name:'idCompania', index:'IdCompania', width:5,hidden:true},
                {name:'referencia', index:'NombreCompania', width:40},
                {name:'servicio', index:'IdServicio', width:35},
                {name:'statusS', index:'id_EstatusCont', width:20,hidden:true},
                {name:'idEtapa', index:'IdEtapa', width:20},
            	{name:'diasP', index:'FechaSysProceso', width:15},
            	{name:'diasE', index:'FechaSysProceso', width:15},
            	{name:'contacto', index:'Contacto', width:35},
            	{name:'telefono',index:'Telefono1Compania',width:35},
            	{name:'gEtapa',index:'idStatu',width:25}
                ],
            pager: jQuery('#pager'),
            hiddengrid: true,
            sortname: 'idCompania',
            rowNum:200,       
            rowList:[200,250,300],
            sortorder: "DESC",
            height: '100%',
            width: '626',
            imgpath: _base_url + 'public/css/jqgrid/flex/images',
            viewrecords: true,
            multiselect: true,
            onSelectRow: function(ids) 
            {
            	if(ids != null) 
            	{
            		var rec = jQuery("#list").getRowData(ids);
            		lol=ids;
            		
            		jQuery("#list_etapas").setGridParam({url : _site_url + '/controlinterno/procesos_data', page : 1, mtype:'POST',postData:{id_compania:rec.idCompania}}).setCaption("Etapas: "+rec.idCompania).trigger('reloadGrid');
            	
            	}
            },
            adjacents: 4,
            jsonReader: { repeatitems : false, idCompania: "0" }
        }).navGrid('#pager',{add:false,del:false,edit:false,search:false,position:"left"})
        
         .navButtonAdd('#pager',{caption:"", buttonimg: _base_url + "public/css/jqgrid/flex/images/text_columns.png", onClickButton:function(){ jQuery("#list").setColumns();} })
         
            .navButtonAdd('#pager',{caption:"Send SMS.", buttonimg: _base_url + "public/img/icons/sms.png", onClickButton:function(){ 
           
        	 var id = jQuery('#list').getGridParam('selarrrow');
        	 if (id.length > 0) {
            	 
        		 var s; 
            	 s = jQuery("#list").getGridParam('selarrrow'); 
            	 var ret = jQuery("#list").getRowData(s[2]);
            	 var miArray = ''; 
                 var companiaMsg = '';
                 
            	 for(var i = 0;i < id.length; i++)
            	 {
            	 	if(miArray.length > 0)
            	 	{
            	 	   miArray= miArray+'-'+jQuery("#list").getRowData(s[i]).idCompania;
            	 	}
            	 	else
            	 	{
            	 	   miArray=jQuery("#list").getRowData(s[i]).idCompania;
            	 	}
                    var  index = i + 1;
            	 	companiaMsg = companiaMsg+index+'.'+jQuery("#list").getRowData(s[i]).referencia+'<br/>';
            	 }

          	      msg = '<font style="color:#1C1C1C;font-weight:600;font-size: 14px">Enviar sms a </font> <br/> <font style="color: #0404B4;font-weight:500;font-size: 10px">'+companiaMsg+'</font>';
                   jConfirm(msg, 'Dialogo de Confirmacion', function (r) {
                   if(r) {
                   	 id=jQuery('#list').getGridParam('selrow');
                     ret = jQuery("#list").getRowData(id);
                           window.location = _site_url + '/controlinterno/sendsms/'+miArray;
                     }
                  });

             }else { jAlert('Debe seleccionar un registro'); }
                      return false; } })  
                      
          
          
          .navButtonAdd('#pager',{caption:"Send Mail.", buttonimg: _base_url + "public/img/icons/mail-ico.png", onClickButton:function(){  
        	 var id = jQuery('#list').getGridParam('selarrrow');
        	 if (id.length > 0) {
            	 
        		 var s; 
            	 s = jQuery("#list").getGridParam('selarrrow'); 
            	 var ret = jQuery("#list").getRowData(s[2]);
            	 var miArray = ''; 
                 var companiaMsg = '';
                 
            	 for(var i = 0;i < id.length; i++)
            	 {
            	 	if(miArray.length > 0)
            	 	{
            	 	   miArray= miArray+'-'+jQuery("#list").getRowData(s[i]).idCompania;
            	 	}
            	 	else
            	 	{
            	 	   miArray=jQuery("#list").getRowData(s[i]).idCompania;
            	 	}
                    var  index = i + 1;
            	 	companiaMsg = companiaMsg+index+'.'+jQuery("#list").getRowData(s[i]).referencia+'<br/>';
            	 }

          	      msg = '<font style="color:#1C1C1C;font-weight:600;font-size: 14px">Enviar email a </font> <br/> <font style="color: #0404B4;font-weight:500;font-size: 10px">'+companiaMsg+'</font>';
                   jConfirm(msg, 'Dialogo de Confirmacion', function (r) {
                   if(r) {
                   	 id=jQuery('#list').getGridParam('selrow');
                     ret = jQuery("#list").getRowData(id);
                           window.location = _site_url + '/controlinterno/sendMail/'+miArray;
                     }
                  });

             }else { jAlert('Debe seleccionar un registro'); }
                      return false; } })
                      

         
        $('#apply_filter').bind('click', applyFilter);
    });
   

 function getCheckedValue(radioObj) 
 {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
   
    
 var flAuto = true;
 var timeoutHnd; 

 function doSearch(ev)
 { 
       if(!flAuto) return; 
       // var elem = ev.target||ev.srcElement; 
       if(timeoutHnd) 
           clearTimeout(timeoutHnd); 
           timeoutHnd = setTimeout(gridReload,500); 
 } 
  
 function enableAutosubmit(state)
 { 
       flAuto = state; 
       jQuery("#submitButton").attr("disabled",state); 
 }
 
 function gridReload()
 { 
	     
          var ct_mask = jQuery("#search_et").val();
    

           var array_search = +ct_mask;
       
       jQuery("#list").setGridParam({url :'<?php echo site_url() ?>/controlinterno/data/'+array_search, page : 1}).trigger('reloadGrid'); 
 }


</script>

<?php
    
    $estapa = $this->metapas->LoadEtapas();
    $estaus = $this->mciestatus->loadEstatus();
 
?>		
<div class="table_container">

<table>
   <tr>
      <td><div id="titulo">Gestion de Control Interno</div></td>
   </tr>
   <tr>
       <td style="background: #D9E6F0;border: 1px solid #C3AA64; height: 23px">&nbsp; 
              <b>Etapa:<b/>
                     <select id='search_et' onChange='doSearch(arguments[0]||event)' >
                          <option></option> 
                          <?php foreach ($estapa as $k): 
                                     if ($k->GetIdEtapa() == 10 || $k->GetIdEtapa() == 11):
                                         echo '<option value="'.$k->GetIdEtapa().'">'.$k->GetNombre().'</option>'; 
                                     endif;
                                 endforeach;?>   
                     </select>
                  
        </td>
   </tr>
<tr>
<td>
         <table id="list" class="scroll">
    </table>
    <div id="pager" class="scroll" style="text-align:center;">
   
    </div>
 </td>
 </tr>

<?php $this->load->view('etapas_ent_list'); ?>
</table>
</div>